package com.ask.threadcase3;

public class MyThread extends Thread {
    static int ticket = 0;

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread.class) {
                if (ticket < 100) {
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println(getName() + "正在售卖第" + ticket  + "张票");
                    ticket++;
                } else
                    break;
            }

        }
    }
}
